package org.elec.mac.service;


import org.elec.mac.page.PageList;
import org.elec.mac.page.PageProperty;
import org.elec.mac.utils.PageUtil;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import org.elec.mac.mapper.SProductMapper;
import org.elec.mac.entity.SProduct;

import java.util.List;
import java.util.Map;

/**
 * @Description:实现类
 * @author 
 * @version 1.0
 * @created 
 */
@Service
public class SProductService extends BaseService<SProduct,SProductMapper> implements InitializingBean {

	@Autowired
	private SProductMapper sProductMapper;
	
	public void afterPropertiesSet() throws Exception {
		this.setBaseMapper(sProductMapper);
	}

	/**
	 *
	 * @param params
	 * @return
	 */
	public List<SProduct> getOtherProductList(Map<String, Object> params) {
		return sProductMapper.getOtherProductList(params);
	}

	public List<Map<String, Object>> productList(Map<String, Object> params) {
		return  sProductMapper.productList(params);
	}

	public PageList<Map<String, Object>> getPageLists(PageProperty pp) {
		int count = sProductMapper.getCount(pp.getParamMap());
		int start = PageUtil.getStart(pp.getNpage(), count, pp.getNpagesize());
		int end = PageUtil.getEnd(pp.getNpage(), count, pp.getNpagesize());
		pp.putParamMap("startrow", start);
		pp.putParamMap("endrow", end);
		pp.putParamMap("pagesize", pp.getNpagesize());//mysql用到的参数
		PageList<Map<String,Object>> pageList = new PageList<Map<String,Object>>(pp, count, sProductMapper.productList(pp.getParamMap()));
		return pageList;
	}

	public List<Map<String, Object>> getProductMaterial(Long pid) {
		return sProductMapper.getProductMaterial(pid);
	}
}
